﻿
var userImpl = require( '../Business/UserImpl' );
/*
 * GET login page
 */

exports.login = function ( req, res ) {
    res.render( 'login', { title: "登录" });
};


/*
 * POST Loign
 */

exports.authen = function ( req, res ) {

    var parameters = req.body;
    if ( !!parameters && parameters["username"] && parameters["password"] ) {

        userImpl.Authen( parameters["username"], parameters["password"] ,function(authened){

            if ( authened == 0 ) { res.send( 'Cannot find the user!' ); }

            else{

                userImpl.GetEmployeeInfoByEmpID( authened, function ( user ) {
                    if ( user != null ) {
                        req.session.CurrentUser = user;

                        res.redirect( '/Home/Index' );
                    } else {
                        res.send( 'Cannot find the user!' );
                    }
                });
            }

        });

        
    } else {
        res.send( 'Please input name and password！' );
    }
};

